
var fs = require('fs')

// 读取文本
var rs = fs.createReadStream('../input.txt', 'utf-8');

rs.on('data', function(chunk){
    console.log('data');
    console.log(chunk);
});

rs.on('end', function(){
    console.log("END");
});

rs.on('error', function(){
    console.log("ERROR");
})


// 写入文本

var ws1 = fs.createWriteStream('output1.txt', 'utf-8');
ws1.write('使用Stream写入文本数据...\n');
ws1.write('END.');
ws1.end();

var ws2 = fs.createWriteStream('output2.txt');
ws2.write(new Buffer('使用Stream写入二进制数据...\n', 'utf-8'));
ws2.write(new Buffer('END.', 'utf-8'));
ws2.end();